/**
 * @param {number[][]} matrix
 * @param {number} target
 * @return {boolean}
 */
 var findNumberIn2DArray = function(matrix, target) {
     let rowlength=matrix.length;
     if(rowlength==0 || matrix[0].length==0){
         return false;
     }
     let row=0;
     let col=matrix[0].length-1;
     while(row<rowlength && col>=0){
        let num = matrix[row][col];
        if(num>target){
            col--;
        }
        else if(num<target){
            row++;
        }
        else{
            return true;
        }
     }
     return false;
 }
 /* var findNumberIn2DArray = function(matrix, target) {
    let length=matrix.length;
    if(length==0){
        console.log('---');
        return false;
    }
    for(let i=0;i<length;i++){
        let arr=matrix[i];
        let length2=arr.length;
        if(length2==0 || target<arr[0]){
            return false;
        }
        else if(target>arr[length2-1]){
            break ;
        }
        else{
            if(binarySearch(arr,target)){
                return true;
            }
        }
    }
    return false;
    function binarySearch(arr,target){
        let head=0,end=arr.length-1;
        while(head<=end){
            let middle=(head+end)/2;
            middle=Math.ceil(middle);
            if(target>arr[middle]){
                head=middle+1;
            }
            else if(target<arr[middle]){
                end=middle-1;
            }
            else{
                return true;
            }
        }
        return false;
    }
}; */
let arr=[[]];
console.log(findNumberIn2DArray(arr,5));